<?php
/**
 * Created by PhpStorm.
 * User: lidan
 * Date: 2018/8/29
 * Time: 上午10:01
 */
namespace frame;

use Predis\Client;
class Redis
{
    protected static $redis;
    protected static $config;

    public static function init($config) {
        if(empty(self::$config)) {
            self::$config = $config;
        }
    }

    public static function getRedis() {
        if(empty(self::$redis)) {
            self::$redis = new Client(self::$config);
        }
        return self::$redis;
    }

    public static function set($key, $value, $expire = null) {
        $redis = self::getRedis();
        $res = $redis->set($key, $value);
        if($res && !empty($expire)) {
            $res = $redis->expire($key, $expire);
        }
        return $res;
    }

    public static function get($key) {
        $redis = self::getRedis();
        return $redis->get($key);
    }

}